package com.ygqh.baby.service.wdtqyb.api;

import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * API基础
 *
 * @className BaseApi
 */
public abstract class BaseApi {

	private final Pattern uriPattern = Pattern.compile("(\\{[^\\}]*\\})");

	public BaseApi() {
	}

	protected abstract ResourceBundle bundle();

	protected String getRequestUri(String key) {
		String url = bundle().getString(key);
		Matcher m = uriPattern.matcher(url);
		StringBuffer sb = new StringBuffer();
		String sub = null;
		while (m.find()) {
			sub = m.group();
			m.appendReplacement(sb, getRequestUri(sub.substring(1, sub.length() - 1)));
		}
		m.appendTail(sb);
		return sb.toString();
	}
}
